import {
	url
} from "../config"
let reqTask;

export function req(api, method = 'GET', data, header = {
	'content-type': 'application/json' //application/x-www-form-urlencoded
}) {

	return new Promise((resolve, reject) => {
		reqTask = uni.request({
			url: url() + api,
			method: method.toUpperCase(),
			data: data,
			header: {
				...header,
				'Authorization': encodeURI('修改为自己的token(key-value)')
			},
			success: (res) => {
				// TODO 修改为自己的处理逻辑
				let result = res.data
				if (result) {
					resolve()
				} else {
					reject()
				}
			},
			fail: (err) => {
				reject()
			}
		})
	})

}

export const getCurrentTask = () => reqTask